__author__ = 'dracher'
import os
import sys
from lxml import etree
from lxml.etree import XMLSyntaxError
from public_parameters import TEST_MATERIAL_PATH
from commFunc import is_Linux

ticket_path = os.path.join(TEST_MATERIAL_PATH, 'Tickets')
error_exist = False

# try:
#     if is_Linux():
#         os.system("kill -9 $(sudo netstat -tlnp|grep 5000|awk '{print $7}'|awk -F '/' '{print $1}')")
# except Excetion as e:
#     print str(e)
    
# .txt~  backup file, need delete
for del_file in os.listdir(ticket_path):
    if del_file.endswith('.txt~'):
        os.remove(os.path.join(ticket_path, del_file))

for a, b, c in os.walk(ticket_path):
    for f in c:
        if not f.startswith('.'):
            fp = os.path.join(a, f)
            try:
                etree.XML(open(fp, 'r').read())
            except XMLSyntaxError as e:
                print fp
                print e
                print "*" * 50
                error_exist = True

if error_exist == True:
    sys.exit()